package com.dd.edu.rabbitmqboot;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @Autowired
    private AmqpTemplate rabbitTemplate;

    @RequestMapping("/send/{message}")
    public String sendMessage(@PathVariable("message") String message){
        System.out.println(message);
        rabbitTemplate.convertAndSend("myExchange", "direct.biz.ex", message);
        return "ok";
    }



}

@Component
class MessageConsumer{
    @RabbitListener(queues = "myQueue" )
    public void loadMessage(String message){
        System.out.println("消息队列推送过来的消息："+ message);
    }
}
